//
//  YCExamStatusCell.m
//  YCSchool
//
//  Created by Kylin on 16/4/30.
//  Copyright © 2016年 yanglinxia. All rights reserved.
//  科目一的第一个cell,试题练习/模拟考试

#import "YCExamStatusCell.h"
@interface YCExamStatusCell()
/**左边的View*/
@property(nonatomic,weak)UIView *leftView;
/**右边的View*/
@property(nonatomic,weak)UIView *rightView;
/**中间的线*/
@property(nonatomic,weak)UIView *middleLine;
@end

static NSInteger const buttonHeight = 23;
@implementation YCExamStatusCell
+ (CGFloat)getCellHeight{
    return 126;
}

- (void)awakeFromNib {
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = [UIColor whiteColor];
        [self setupChildViews];
    }
    
    return self;
}

// 添加子控件
- (void)setupChildViews{
    [self setupLeftView];
    [self setupRightView];
    [self setupMiddleLine];
    
    [_leftView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.bottom.equalTo(self.contentView);
        make.right.equalTo(_middleLine.mas_left);
        make.width.equalTo(_rightView);
    }];
  
    [_middleLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@2);
        make.height.equalTo(@48);
        make.centerY.equalTo(self.contentView);
        make.centerX.equalTo(self.contentView);
    }];
    
    [_rightView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_middleLine.mas_right);
        make.top.right.bottom.equalTo(self.contentView);
    }];
    
}

// 添加中间线
- (void)setupMiddleLine{
    UIView *middleLine = [[UIView alloc]init];
    _middleLine = middleLine;
    middleLine.backgroundColor = [UIColor yc_colorWithUInt:0xB3B3B3];
    
    [self.contentView addSubview:middleLine];
    
}
// 添加左边的View
- (void)setupLeftView{
    
    UIView *leftView = [[UIView alloc]init];

    _leftView = leftView;
    
    UILabel *topLabel = [self commonTopLabelWithTitle:@"完成试题"];
    topLabel.font = [UIFont systemFontOfSize:14];
    [_leftView addSubview:topLabel];
    
     UILabel *middleLabel = [self commonMiddleLabelWithText:@"620/725"];
    middleLabel.font = [UIFont systemFontOfSize:11];
    [_leftView addSubview:middleLabel];
    
    UIButton *button = [self commonBottomButtonWithBgColor:[UIColor yc_colorWithRed:255 Green:101 Blue:108] title:@"及格次数"];
    button.titleLabel.font = [UIFont systemFontOfSize:13];
    [button addTarget:self action:@selector(leftButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [_leftView addSubview:button];
    [self.contentView addSubview:leftView];
    
    
    // 调用约束方法的View
    [self makemakeConstraintsWithTopLabel:topLabel middleLabel:middleLabel button:button inView:leftView];
}

// 添加右边的view
- (void)setupRightView{
    
    UIView *rightView = [[UIView alloc]init];

    _rightView = rightView;
    UILabel *topLabel = [self commonTopLabelWithTitle:@"及格次数"];
     topLabel.font = [UIFont systemFontOfSize:14];
    [_rightView addSubview:topLabel];
    
    UILabel *middleLabel = [self commonMiddleLabelWithText:@"18/20"];
     middleLabel.font = [UIFont systemFontOfSize:11];
    [_rightView addSubview:middleLabel];
    
    UIButton *button = [self commonBottomButtonWithBgColor:[UIColor yc_colorWithRed:0 Green:210 Blue:197] title:@"模拟考试"];
    button.titleLabel.font = [UIFont systemFontOfSize:13];
    [button addTarget:self action:@selector(rightButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [_rightView addSubview:button];
    
    [self.contentView addSubview:rightView];
    
    // 调用约束方法的View
    [self makemakeConstraintsWithTopLabel:topLabel middleLabel:middleLabel button:button inView:rightView];
}

// 添加顶部label的通用方法
- (UILabel*)commonTopLabelWithTitle:(NSString *)title{
    UILabel *topLabel = [[UILabel alloc]init];
    topLabel.textColor  = [UIColor yc_colorWithUInt:0x4D4D4D];
    topLabel.text = title;
    return topLabel;
}

// 添加中间Label通用方法
- (UILabel *)commonMiddleLabelWithText:(NSString *)text{
    UILabel *middleLabel = [[UILabel alloc]init];
    middleLabel.textColor = [UIColor yc_colorWithUInt:0xB3B3B3];
    middleLabel.text = text;
    middleLabel.font = [UIFont systemFontOfSize:14];
    
    return middleLabel;
}

// 添加度部按钮的通用方法
- (UIButton *)commonBottomButtonWithBgColor:(UIColor *)color title:(NSString *)title{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [button setBackgroundColor:color];
    [button setTitle:title forState:UIControlStateNormal];
     button.layer.cornerRadius = buttonHeight / 2;
    return button;
}

#pragma mark- 设置约束的通用方法
- (void)makemakeConstraintsWithTopLabel:(UILabel *)topLabel middleLabel:(UILabel *)middleLabel button:(UIButton *)button inView:(UIView *)view{
    [topLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(view);
        make.top.equalTo(view).offset(29);
        make.height.equalTo(@14);
    }];
    
    [middleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(view);
        make.top.equalTo(topLabel.mas_bottom).offset(6);
        make.height.equalTo(@11);
    }];
    
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(middleLabel.mas_bottom).offset(10);
        make.left.equalTo(view).offset(35);
        make.width.equalTo(@115);
        make.bottom.equalTo(view).offset(-33);
    }];

}

#pragma mark- 监听按钮的点击方法
- (void)leftButtonClick{
    YCLogFunc
}

- (void)rightButtonClick{
    YCLogFunc
}
@end
